<?php
class Form_Group extends Ext_Form
{
    protected $_member;
    protected $_group;

    public function __construct($member = null, Model_Group $group = null)
    {
        $this->_member = $member;
        $this->_group = $group;
        parent::__construct();
    }

    public function init()
    {
        $this->setName('group');

        $this->addElement('text', 'name', array(
            'label'      => 'group_name',
            'required'   => true,
            'filters'    => array('StringTrim'),
            'validators' => array('NotEmpty')
        ));

        $this->addElement('tinyMCE', 'description', array(
            'label'    => 'description',
            'cols'     => '50',
            'rows'     => '5',
            'required' => true,
            'filters'  => array('StringTrim'),
            'tinyMCE'  => array(
                 'mode'  => "textareas",
                 'theme' => "simple"
            )
        ));

//        $this->addElement('file', 'logo', array(
//            'label'       => 'group_img',
//            'destination' => Ext_App::getSetting('paths.uploads'),
//            'validators'  => array(
//                array('Extension', false, 'jpg, png, gif, jpeg'),
//            )
//        ));

        $this->addElement('submit', 'save');
    }

    public function save()
    {
        if ($this->_group) {
            $group = $this->_group;
        } else {
            $group = Ext_App::getTable('Model_DbTable_Group')->createRow();
            $group->creator_id = $this->_member->id;
        }
        $group
            ->setFromArray($this->getValues())
            ->save()
        ;
        return $group->id;
    }
}